<template>
  <div>
    <el-form label-position="top" ref="form" :model="form" label-width="80px">
      <el-form-item label="分组名称">
        <el-input v-model="form.name" size="small" placeholder="请输入分组名称"></el-input>
      </el-form-item>
    </el-form>
    <div class="menu-navbar">
      <el-button size="small" type="primary" :loading="isloading" @click="createSubmitProject">确 定</el-button>
      <el-button size="small" @click="closeSubmitProject">取 消</el-button>
    </div>
  </div>
</template>

<script>
  import {
    addGroupItem
  } from '@/api/apiModel/api.js'
  export default {
    name: 'apiTreeAddGroup',
    props: {
      addGropdata: {}
    },
    data() {
      return {
        isloading: false,
        form: {
          name: '',
          parentId: '',
          projectId: this.$store.state.user.projectId
        }
      }
    },
    mounted() {
      if (this.addGropdata.id) {
        this.form.parentId = this.addGropdata.id
      }
    },
    methods: {
      createSubmitProject() { // 确定新增按钮
        addGroupItem(this.form).then(res => {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.$emit('closeDialog')
          this.$emit('fetchData')
        })
      },
      closeSubmitProject() { // 取消按钮
        this.$emit('closeDialog')
      }
    }
  }
</script>

<style scoped>
  .menu-navbar{
    text-align: right;
  }
</style>
